﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Web;

namespace App.MVC.App_Start
{
    public static class Verification
    {
        #region 通过Hash值来验证文件是否被篡改
        /// <summary>
        /// 通过Hash值来验证文件是否被篡改
        /// </summary>
        /// <param name="argFilePath">文件路径</param>
        /// <returns>输出Hash值</returns>
        public static string GetFileHash(string argFilePath)
        {
            using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
            using (FileStream fs = new FileStream(argFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                return BitConverter.ToString(md5.ComputeHash(fs)).Replace("-", "");
            }
        }

        #endregion
        //public static void Empty(this System.IO.DirectoryInfo directory)
        //{
        //    foreach (System.IO.FileInfo file in directory.GetFiles()) file.Delete();
        //    foreach (System.IO.DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
        //}
    }
}